/***************************************************************************************************
 *Copyright(C),2021-2026,Sumscope
 *FileName    :  PanoramicDataCenter.cpp
 *Author    :  shangyi.xin
 *Version    :  1.0
 *Date        :  2021/04/09
 *Desc        :  //用于主要说明此程序文件完成的主要功能
 *Relation :
 *Others    :  //其他内容说明
 *Function :  //主要函数列表，每条记录应包含函数名及功能简要说明
 *History    :
 * //修改历史记录列表，每条修改记录应包含修改日期、修改者及修改内容简介
 ***************************************************************************************************/
#define NOMINMAX
#include "PanoramicDataCenter.h"

#include <core/time/date.h>
#include <qbtools/tools.h>

#include "../BondHisMarketStream.h"

CPanoramicDataCenter::CPanoramicDataCenter() { initialize(); }

qb::base::CSLock& CPanoramicDataCenter::GetLock(bool bForceToday) {
  if (IsHistoryDate() && !bForceToday) {
    return m_hisContainer.GetLock();
  } else {
    return CPanoramicBondDealContainer::instance().GetLock();
  }
}

bool CPanoramicDataCenter::ChangeDate(int date) {
  if (date == m_nCurrentDate) return false;
  m_nCurrentDate = date;
  ReloadHisContainer();
  return true;
}

void CPanoramicDataCenter::ReloadData() {
  if (IsHistoryDate()) {
    ReloadHisContainer();
  } else {
    // 暂不处理
  }
}

void CPanoramicDataCenter::GetDisChartData(int nType, time_t tNow,
                                           CDealDisChartList& data,
                                           bool eng /*= false*/) {
  if (!IsHistoryDate()) {
    return CPanoramicBondDealContainer::instance().GetDisChartData(nType, tNow,
                                                                   data, eng);
  } else {
    return m_hisContainer.GetDisChartData(
        nType, qb::base::IntDate::IntToTime(m_nCurrentDate), data, eng);
  }
}

CPanoramicBondDealMap& CPanoramicDataCenter::GetDealMap(bool bForceToday) {
  if (IsHistoryDate() && !bForceToday) {
    return m_hisContainer.GetDealMap();
  } else {
    return CPanoramicBondDealContainer::instance().GetDealMap();
  }
}

void CPanoramicDataCenter::initialize() {
  m_nCurrentDate = 0;
  m_hisContainer.SetHistory();
}

bool CPanoramicDataCenter::IsHistoryDate() {
  if (m_nCurrentDate == 0) return false;
  return m_nCurrentDate != CMarketStream::GetBondDealInvalidateDay();
}

void CPanoramicDataCenter::ReloadHisContainer() {}
